﻿using UnityEngine;
using System.Collections;

namespace Lost{
	public class II_Pedestal : InteractiveItem {
		[SerializeField] string targetName = "RightHand";
		Transform targetTran;
		Coroutine curCor;
		public override void Interact (HitInf hitInf)
		{
			if (targetTran == null) {
				targetTran = ItemsManager.FindTransform (targetName);
			}
			if (curCor == null) {
				curCor = StartCoroutine (MoveWithTarget (targetTran));
			}
		}
		IEnumerator MoveWithTarget(Transform tr){
			Vector3 prePos = tr.position;
			while (!LostInput.GetInputEvent (InputEvent.Release)) {
				Vector3 moveDir = tr.position - prePos;
				float moveDis = Vector3.Dot (moveDir, transform.right);
				transform.Translate (transform.right * moveDis);
				prePos = tr.position;
				yield return null;
			}
			curCor = null;
		}
	}
}
